home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_dos.lha / dos / sphsrc.v08 / sph_intense.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-26  |  1.9 KB  |  61 lines

  1. #include "HEADERS.h"
  2. /**********************
  3.                       *
  4.  File                 * intensity.c
  5.                       * calculates intensity for each object
  6.                       *
  7.                       * takes the list of objects and calculates Gouraud
  8.                       *    intensities (flat shading)
  9.                       * 
  10.                       * changes objects intensity
  11.                       * needs to be called after clip (to get the bounds)
  12.               *
  13.                       *********************************************************/
  14.  
  15. /**********************
  16.                       *
  17.  Includes          *
  18.                       *
  19.                       *********************************************************/
  20.  
  21. #include <stdio.h>
  22. #include "sphigslocal.h"
  23. #include <assert.h>
  24.  
  25.  
  26. /**********************
  27.                       *
  28.  Function          * calc_intensity
  29.                       *
  30.                       * calculates the intensity for each object
  31.               *
  32.                       *********************************************************/
  33. void SPH__calc_intensity (view_spec *vs)
  34. {
  35.      MAT3hvec negatedVector;
  36.      MAT3hvec centerFace;
  37.      MAT3hvec oddNormal;
  38.      register obj *scanObj;
  39.      double temp;
  40.      
  41.      scanObj = vs->objects;
  42.      
  43.      while (scanObj != NULL) {
  44.       if (scanObj->type == objFace) {
  45.            centerFace[X] = ( scanObj->max[X] + scanObj->min[X] ) / 2;
  46.            centerFace[Y] = ( scanObj->max[Y] + scanObj->min[Y] ) / 2;
  47.            centerFace[Z] = ( scanObj->max[Z] + scanObj->min[Z] ) / 2;
  48.            centerFace[3] = 1;
  49.            MAT3_SUB_VEC (negatedVector, 
  50.                  vs->uvn_point_light_source, centerFace );
  51.            negatedVector[3] = 1;
  52.            MAT3_NORMALIZE_VEC( negatedVector, temp );
  53.            MAT3_COPY_VEC ( oddNormal, scanObj->normal );
  54.            oddNormal[3] = 1;
  55.            MAT3_NORMALIZE_VEC( oddNormal, temp );
  56.            scanObj->intensity = MAT3_DOT_PRODUCT(negatedVector, oddNormal );
  57.       }
  58.       scanObj = scanObj->next;
  59.      }
  60. }
  61.